//
//  SendGiftViewController.m
//  marrymarry
//
//  Created by lsj on 16/10/13.
//  Copyright © 2016年 cf. All rights reserved.
//

#import "SendGiftViewController.h"
#import "TopUpViewController.h"
@interface SendGiftViewController ()<UIWebViewDelegate>
@property (weak, nonatomic) IBOutlet UILabel *myTitleLabel;

@end

@implementation SendGiftViewController


-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = YES;
    self.navigationController.navigationBar.hidden = YES;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.myTitleLabel.text = @"送礼物";
    
    UIWebView *myWeb = [[UIWebView alloc] initWithFrame:CGRectMake(0,64,ScreenWidth,ScreenHeight-64 )];
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@?from=%@&to=%@",SENDGIFTS_URL,self.fromStr,self.toStr]]];
    [myWeb setDelegate:self];
    myWeb.scalesPageToFit = YES;
    [myWeb loadRequest:request];
    [self.view addSubview:myWeb];
}
- (IBAction)getBackVC:(UIButton *)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;
{
    NSLog(@"%@",[NSString stringWithFormat:@"%@",request.URL]);
    NSString * myUrlStr = [NSString stringWithFormat:@"%@",request.URL];
    NSString * signStr ;
    if ([myUrlStr rangeOfString:@"?"].location == NSNotFound) {
        signStr = [[myUrlStr componentsSeparatedByString:@"com"] lastObject];
        if ( [signStr isEqualToString:@"3"]) {
            NSLog(@"约币不足");
//            [SVProgressHUD showInfoWithStatus:@"约币不足！请先充值！"];
            UIStoryboard * TopUpSB = [UIStoryboard storyboardWithName:@"TopUpViewController" bundle:nil];
            TopUpViewController * TopUpVC  = [TopUpSB instantiateViewControllerWithIdentifier:@"TopUpViewController"];
            self.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:TopUpVC animated:YES];

            return NO;
        }else if ([signStr isEqualToString:@"1"])
        {
            NSLog(@"送礼成功");
            [SVProgressHUD showSuccessWithStatus:@"送礼成功！"];
            [self.navigationController popViewControllerAnimated:YES];
            return NO;
        }else
        {
            NSLog(@"送礼失败");
            [SVProgressHUD showErrorWithStatus:@"送礼失败。。请稍后重试"];
            return NO;
        }
    }
    else
    {
    
    return YES;
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
